/**   
 * @Title: ViewerUtil.java 
 * @Package com.esun.util 
 * @Description: (视图工具类,存放通用视图类工具) 
 * @author 程相亭 <br/>
 * @date 2012-03-13 下午05:07:33  
 * copy right 深圳市易讯天空网络技术有限公司
 */
package com.esun.util;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.esun.cheetah.R;
import com.esun.cheetah.config.Language;
import com.esun.cheetah.view.HomeAct;
import com.esun.cheetah.view.personal.PersonalAct;
import com.esun.util.log.EDebug;

/**
 * com.esun.util.ViewerUtil
 * 
 * @Description: (视图工具类,存放通用视图类工具)
 * @author 程相亭 <br/>
 * @date 2012-03-13 下午05:07:33
 * 
 */
public class ViewerUtil {

	private static boolean IS_DIALOG_SHOW = false;
	public static boolean isShowRegist = false;

	public static void showTipDialog(final Context context, String strMsg,
			final boolean isActEnd) {
		EDebug.o("这是一个dialog");
		final Dialog popTipDialog = new Dialog(context, R.style.dialog);
		popTipDialog.getWindow().setContentView(
				R.layout.viewerutil_dialog_showtipdialog);
		if (!IS_DIALOG_SHOW && !((Activity) context).isFinishing()) {
			EDebug.o("这是一个dialog");
			popTipDialog.show();
			IS_DIALOG_SHOW = true;
			TextView tvMsg = (TextView) popTipDialog.getWindow().findViewById(
					R.id.viewerutildialogshowtipdialog_tv_msg);
			tvMsg.setText(strMsg);
			Button btnOk = (Button) popTipDialog.getWindow().findViewById(
					R.id.viewerutildialogshowtipdialog_btn_ok);
			btnOk.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					popTipDialog.dismiss();
					IS_DIALOG_SHOW = false;
				}
			});

			popTipDialog
					.setOnDismissListener(new DialogInterface.OnDismissListener() {

						@Override
						public void onDismiss(DialogInterface dialog) {
							// TODO Auto-generated method stub
							IS_DIALOG_SHOW = false;
							if (isActEnd) {
								((Activity) context).finish();
							}
						}
					});
		}
	}

	public static void showLogoffDialog(final Context context) {
		final Dialog logoutDialog = new Dialog(context, R.style.dialog);
		logoutDialog.getWindow().setContentView(
				R.layout.viewerutil_dialog_showlogout);
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {
				case R.id.cancel:
					logoutDialog.dismiss();
					break;

				case R.id.sure:
					logoutDialog.dismiss();
					Intent intent = new Intent();
					intent.setClass((Activity) context, HomeAct.class);

					HomeAct.flag = Language.FLAG_ONE;
					PersonalAct.flag = Language.FLAG_FIVE;
					context.startActivity(intent);

					break;
				default:
					break;
				}
			}
		};
		Button btnCancel = (Button) logoutDialog.getWindow().findViewById(
				R.id.cancel);
		btnCancel.setOnClickListener(listener);
		Button btnRecharge = (Button) logoutDialog.getWindow().findViewById(
				R.id.sure);
		btnRecharge.setOnClickListener(listener);

		logoutDialog.show();
	}

	public static void showRechargSZXDialog(final Context context) {
		final Dialog logoutDialog = new Dialog(context, R.style.dialog);
		logoutDialog.getWindow().setContentView(
				R.layout.viewerutil_dialog_rechargszx);
		OnClickListener listener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {
				case R.id.dialog_recharg_gc:
					logoutDialog.dismiss();
					Intent intent_gc = new Intent();
					intent_gc.setClass((Activity) context,com.esun.cheetah.view.personal.sportlotteryfootball.SportteryFootballAgp.class);
					Bundle bundleToSportteryFootbal = new Bundle();
		      bundleToSportteryFootbal.putInt("CURRENT_TAB_NUM", 0);
		      intent_gc.putExtras(bundleToSportteryFootbal);
		      EDebug.o(this, "click to shuangseqiu choose");
		      context.startActivity(intent_gc);
		      break;
				case R.id.dialog_recharg_ckye:
					logoutDialog.dismiss();
					Intent intent = new Intent();
					intent.setClass((Activity) context, HomeAct.class);
					intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					context.startActivity(intent);

					break;
				default:
					break;
				}
			}
		};
		Button btnCKYE = (Button) logoutDialog.getWindow().findViewById(
				R.id.dialog_recharg_ckye);
		btnCKYE.setOnClickListener(listener);
		Button btnRechargeGC = (Button) logoutDialog.getWindow().findViewById(
				R.id.dialog_recharg_gc);
		btnRechargeGC.setOnClickListener(listener);
		logoutDialog.show();
	}

	public static void showLogoutDialog(final Context context) {
		final Dialog logoutDialog = new Dialog(context, R.style.dialog);
		logoutDialog.getWindow().setContentView(
				R.layout.viewerutil_dialog_showlogout);
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {
				case R.id.cancel:
					logoutDialog.dismiss();
					break;

				case R.id.sure:
					logoutDialog.dismiss();
					Intent intent = new Intent();
					intent.setClass((Activity) context, HomeAct.class);

					HomeAct.flag = Language.FLAG_ONE;
					PersonalAct.flag = Language.FLAG_FIVE;
					context.startActivity(intent);

					break;
				default:
					break;
				}
			}
		};
		Button btnCancel = (Button) logoutDialog.getWindow().findViewById(
				R.id.cancel);
		btnCancel.setOnClickListener(listener);
		Button btnRecharge = (Button) logoutDialog.getWindow().findViewById(
				R.id.sure);
		btnRecharge.setOnClickListener(listener);

		logoutDialog.show();
	}

	public static ProgressDialog showProgressDialog(Context context, String msg) {
		System.out.println(11);
		ProgressDialog progress = null;
		System.out.println(12);
		progress = new ProgressDialog(context);
		System.out.println(13);
		// progress.getWindow().setContentView(R.layout.progress_dialog);
		progress.setMessage(msg);
		System.out.println(14);
		// TextView tvMsg =
		// (TextView)progress.getWindow().findViewById(R.id.progress_dialog_msg);
		// tvMsg.setText(msg);

		// progress.setOnKeyListener(new DialogInterface.OnKeyListener() {
		//
		// @Override
		// public boolean onKey(DialogInterface dialog, int keyCode,
		// KeyEvent event) {
		//
		// return true;
		//
		// }
		// });

		return progress;
	}

	// /**
	// * @Title: showProgressDialog
	// * @Description: 进度框
	// * @param Context activity环境
	// * String 要提示的信息
	// * @return ProgressDialog 进度框
	// * @throws
	// */
	// public static ProgressDialog showProgressDialog(Context context, String
	// msg) {
	//
	// ProgressDialog progress = null;
	// progress = new ProgressDialog(context);
	// progress.setMessage(msg);
	//
	// progress.setOnKeyListener(new DialogInterface.OnKeyListener() {
	//
	// @Override
	// public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)
	// {
	//
	// return true;
	//
	// }
	// });
	//
	// return progress;
	// }

	// /**
	// * @Title: showTipDialog
	// * @Description: 提示框
	// * @param Context activity环境
	// * String 要提示的信息
	// * boolean 是否关闭
	// * @return
	// * @throws
	// */
	// public static void showTipDialog(final Context context, String strMsg,
	// final boolean isActEnd) {
	// final Dialog popTipDialog = new Dialog(context, R.style.dialog);
	// popTipDialog.getWindow().setContentView(R.layout.viewerutil_dialog_showtipdialog);
	// if (!IS_DIALOG_SHOW&&!((Activity) context).isFinishing()) {
	// popTipDialog.show();
	// IS_DIALOG_SHOW = true;
	// TextView tvMsg = (TextView)
	// popTipDialog.getWindow().findViewById(R.id.viewerutildialogshowtipdialog_tv_msg);
	// tvMsg.setText(strMsg);
	//
	// Button btnOk = (Button)
	// popTipDialog.getWindow().findViewById(R.id.viewerutildialogshowtipdialog_btn_ok);
	// btnOk.setOnClickListener(new View.OnClickListener() {
	//
	// @Override
	// public void onClick(View v) {
	// popTipDialog.dismiss();
	// IS_DIALOG_SHOW = false;
	// }
	// });
	//
	// popTipDialog.setOnDismissListener(new DialogInterface.OnDismissListener()
	// {
	//
	// @Override
	// public void onDismiss(DialogInterface dialog) {
	// // TODO Auto-generated method stub
	// IS_DIALOG_SHOW = false;
	// if (isActEnd) {
	// ((Activity) context).finish();
	// }
	// }
	// });
	// }
	// }

}
